<?php
/*
 *author:Yangligao
 *Date:2013-9-24
 */
require '../../Config.php';
$flag = $_GET['flag'];
if($flag == 'display'){
	$smarty->display("Admin/ChangeAdminPwd.html");
}else if($flag == 'update'){
	
	if($_POST['reNewPwd'] == $_POST['newPwd']){
		$adminModel = new AdminModel();
		
		//根据用户id查出用户密码
		$res = $adminModel->admin_select('admin_pwd','where admin_id='.$_SESSION['id']);
		
		//判断密码的正确与否
		
		if(base64_decode($res[0]['admin_pwd']) == $_POST['oldPwd']){
			
			//如果输入的旧密码与原始密码相等
			$arr['admin_pwd'] = base64_encode($_POST['newPwd']);
			$arr['admin_id'] = $_SESSION['id'];
			$res = $adminModel->admin_update($arr);
			if($res){
				jump("密码修改成功", $_SERVER['HTTP_REFERER']);
			}else{
				alertInfo('密码修改失败！', $_SERVER['HTTP_REFERER']);
			}
			
			
		}else{
			alertInfo('原始密码输入错误！', $_SERVER['HTTP_REFERER']);
			
		}
	}else{
		alertInfo('两次密码不一致！', $_SERVER['HTTP_REFERER']);
	}
}

?>
